//
//  CLAttributeChangingView.m
//  MasonryTest
//
//  Created by Charles on 16/9/23.
//  Copyright © 2016年 Charles. All rights reserved.
//

#import "CLAttributeChangingView.h"

@implementation CLAttributeChangingView

- (instancetype)init{
    if (self = [super init]) {
        [self makeView];
    }
    return self;
}

- (void)makeView{
    UIView *greenView = UIView.new;
    greenView.backgroundColor = UIColor.greenColor;
    greenView.layer.borderColor = UIColor.blackColor.CGColor;
    greenView.layer.borderWidth = 2;
    [self addSubview:greenView];
    
    UIView *redView = UIView.new;
    redView.backgroundColor = UIColor.redColor;
    redView.layer.borderColor = UIColor.blackColor.CGColor;
    redView.layer.borderWidth = 2;
    [self addSubview:redView];
    
    UIView *blueView = UIView.new;
    blueView.backgroundColor = UIColor.blueColor;
    blueView.layer.borderColor = UIColor.blackColor.CGColor;
    blueView.layer.borderWidth = 2;
    [self addSubview:blueView];
    
    UIView *superview = self;
    UIEdgeInsets padding = UIEdgeInsetsMake(15, 10, 15, 10);

    [greenView makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.equalTo(superview).insets(padding);
        make.bottom.equalTo(blueView.top).insets(padding);
        make.right.equalTo(redView.left).insets(padding);
        make.width.equalTo(redView.width);
        
        make.height.equalTo(@[redView,blueView]);
    }];
    
    [redView makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.right.equalTo(superview).insets(padding);
        make.left.equalTo(greenView.right).insets(padding);
        make.bottom.equalTo(blueView.top).insets(padding);
        
        make.height.equalTo(@[greenView,blueView]);
    }];
    
    [blueView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(greenView.bottom).insets(padding);
        make.left.right.and.bottom.equalTo(superview).insets(padding);
        
        make.height.equalTo(@[greenView,redView]);
    }];
    
}

@end
